package com.purong.purong.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by wenjiezeng on 2017/11/3.
 */
public class StatusBarUtil {
    public static void setStatusBarTran(Activity activity){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setStatusBarTranAPI21(activity);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setStatusBarTranAPI19(activity);
        }
    }

    // 5.0版本以上
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static void setStatusBarTranAPI21(Activity activity) {
        Window window = activity.getWindow ();
        window.clearFlags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.getDecorView ()
                .setSystemUiVisibility (
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags (WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor (Color.TRANSPARENT);
    }
    // 4.4 - 5.0版本
    private static void setStatusBarTranAPI19(Activity activity) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    }

}
